home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.04 Apr 91 / Code Optimizing / Sources / Dummy.a next >
Encoding:
Text File  |  1990-04-28  |  6.4 KB  |  171 lines  |  [TEXT/MPS ]

  1.       PRINT OFF
  2.       INCLUDE 'Traps.a'
  3.       INCLUDE 'SANEMacs.a'
  4.       PRINT ON
  5. ;-------------------------------------------------
  6. DUMMY       PROC        EXPORT
  7. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  8. ;  Performs the matrix multiplication C = A * B.
  9. ;
  10. ;  (This is a DUMMY version which does no
  11. ;  floating-point arithmetic; it is used for
  12. ;  measuring the amount of indexing overhead.)
  13. ;
  14. ;  Calling sequence (FORTRAN):
  15. ;      CALL DUMMY (A, B, C, L, M, N)
  16. ;
  17. ;  where
  18. ;      A is an array with L rows and M columns
  19. ;      B is an array with M rows and N columns
  20. ;      C is an array with L rows and N columns
  21. ;      L, M, and N are INTEGERs.
  22. ;
  23. ;  NOTE:  All arrays must be completely filled,
  24. ;  with no gaps.  Do not try to pass part of an
  25. ;  array unless it forms a contiguous block of
  26. ;  memory locations.
  27. ;
  28. ;  April 1990
  29. ;  Jon Bell, Dept. of Physics & Computer Science
  30. ;  Presbyterian College, Clinton SC 29325
  31. ;
  32. ;  Written for MPW Assembler, v3.0.
  33. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  34. ;  Locations of arguments to the subroutine,
  35. ;  relative to the address stored in register A6.
  36. a       EQU     28          ; addr. of a
  37. b       EQU     24          ; addr. of b
  38. c       EQU     20          ; addr. of c
  39. l       EQU     16          ; addr. of # rows in a
  40. m       EQU     12          ; addr. of # cols in a
  41. n       EQU     8           ; addr. of # cols in b
  42. ;  Locations of local variables, relative to the
  43. ;  address stored in register A6.
  44. sum         EQU -10 ; accumulates an element of c
  45. term        EQU -20 ; terms for an element of c
  46. termCount   EQU -24 ; initial value of term index
  47. rowCount    EQU -28 ; initial value of col. index
  48. aColSize    EQU -32 ; # of bytes per column of a
  49. bColSize    EQU -36 ; # of bytes per column of b
  50. ;  Other constants.
  51. ParamSize   EQU  24 ; # of bytes of parameters
  52. LocalSize   EQU -36 ; # of bytes of local var's.
  53. ;  Register usage.
  54. aPtr        EQU  A2 ; pointer into a
  55. bPtr        EQU  A3 ; pointer into b
  56. cPtr        EQU  A4 ; pointer into c
  57. rowIndex    EQU  D3 ; row-loop index
  58. colIndex    EQU  D4 ; column-loop index
  59. termIndex   EQU  D5 ; term-loop index
  60. aRowBase    EQU  D6 ; start of current row in a
  61. bColBase    EQU  D7 ; start of current col. in b
  62. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  63. ;  Set up the stack frame, and save registers on
  64. ;  the stack.
  65.       LINK        A6, #LocalSize
  66.       MOVEM.L     A2-A4/D3-D7, -(SP)
  67. ;  Calculate and save the length of one 
  68. ;  column of a.
  69.       MOVE.L      l(A6), A0
  70.       MOVE.L      (A0), D0      ; # of rows
  71.       MULU        #10, D0       ; bytes per column
  72.       MOVE.L      D0, aColSize(A6)
  73. ;  Calculate and save the length of one 
  74. ;  column of b.
  75.       MOVE.L      m(A6), A0
  76.       MOVE.L      (A0), D0      ; # of rows
  77.       MULU        #10, D0       ; bytes per column
  78.       MOVE.L      D0, bColSize(A6)
  79. ;  Save the initial value of the term index.
  80.       MOVE.L      m(A6), A0
  81.       MOVE.L      (A0), termCount(A6)
  82. ;  Save the initial value of the row index.
  83.       MOVE.L      l(A6), A0
  84.       MOVE.L      (A0), rowCount(A6)
  85. ;  Initialize the column index.
  86.       MOVE.L      n(A6), A0
  87.       MOVE.L      (A0), colIndex
  88. ;  Initialize the base address of the current
  89. ;  column in b to the start of b.
  90.       MOVE.L      b(A6), bColBase
  91. ;  Initialize pointer into c.
  92.       MOVE.L      c(A6), cPtr
  93. BeginColLoop      ;  Cycle over the columns of c.
  94.             SUB.L       #1, colIndex
  95.             BMI.S       EndColLoop
  96.       ;  Initialize the row index.
  97.             MOVE.L      rowCount(A6), rowIndex
  98.       ;  Initialize the base address of the
  99.       ;  current row in a to the start of a.
  100.             MOVE.L      a(A6), aRowBase
  101. BeginRowLoop      ; Cycle over the rows of c.
  102.                   SUB.L       #1, rowIndex
  103.                   BMI.S       EndRowLoop
  104.             ;  Initialize the a and b pointers 
  105.             ;  for the next sum of terms.
  106.                   MOVE.L      aRowBase, aPtr
  107.                   MOVE.L      bColBase, bPtr
  108.             ;  Initialize the sum.
  109.                   LEA         sum(A6), A0
  110.                   CLR.L       (A0)+
  111.                   CLR.L       (A0)+
  112.                   CLR.W       (A0)
  113.             ;  Initialize the term index.
  114.                   MOVE.L  termCount(A6), termIndex
  115. BeginTermLoop     ; Cycle over the terms 
  116.                   ; in the sum.
  117.                         SUB.L       #1, termIndex
  118.                         BMI.S       EndTermLoop
  119.                   ;  Push the source and
  120.                   ;  destination addresses on the
  121.                   ;  stack for the multiplication.
  122.                   ;     MOVE.L      aPtr, -(SP)
  123.                         LEA         term(A6), A0
  124.                   ;     MOVE.L      A0, -(SP)
  125.                   ;  Copy the current element of b
  126.                   ;  to the destination, and
  127.                   ;  advance to the next element
  128.                   ;  in the current column of b.
  129.                         MOVE.L      (bPtr)+, (A0)+
  130.                         MOVE.L      (bPtr)+, (A0)+
  131.                         MOVE.W      (bPtr)+, (A0)
  132.                   ;  Perform the multiplication.
  133.                   ;     FMULX
  134.                   ;  Add the new term to the sum.
  135.                   ;     PEA         term(A6)
  136.                   ;     PEA         sum(A6)
  137.                   ;     FADDX
  138.                   ;  Advance to the next element
  139.                   ;  in the current row of a.
  140.                         ADDA.L  aColSize(A6), aPtr
  141.                         BRA.S       BeginTermLoop
  142. EndTermLoop
  143.             ;  Move the sum into the current
  144.             ;  element of c, and advance to the
  145.             ;  next row in the current column of
  146.             ;  c.  (At the end of the current
  147.             ;  column, this will wrap around to
  148.             ;  the next column.)
  149.                   LEA         sum(A6), A0
  150.                   MOVE.L      (A0)+, (cPtr)+
  151.                   MOVE.L      (A0)+, (cPtr)+
  152.                   MOVE.W      (A0), (cPtr)+
  153.             ;  Advance to the next row of a.
  154.                   ADD.L       #10, aRowBase
  155.                   BRA.S       BeginRowLoop
  156. EndRowLoop
  157.       ;  Advance to the next column of b.
  158.             ADD.L       bColSize(A6), bColBase
  159.             BRA.S       BeginColLoop
  160. EndColLoop
  161. ;  All done.  Restore the saved registers, 
  162. ;  clean up the stack and return.
  163.       MOVEM.L     (SP)+, A2-A4/D3-D7
  164.       UNLK        A6
  165.       MOVE.L      (SP)+, A0
  166.       ADDA.L      #ParamSize, SP
  167.       JMP         (A0)
  168.       DC.B        'DUMMY   '  ; label for debugger
  169.       ENDPROC
  170.       END
  171.